class_name PalsyState
extends AnomalyState


## 每_damage_interval秒造成_damage_degree最大生命值的雷属性伤害（最小为1），
## 同时降低_reduce_resistance的雷属性抗性，并降低_reduce_speed的移动速度，持续duration秒。


@export var _damage_degree: float
@export var _damage_interval: float
@export var _reduce_resistance: float
@export var _reduce_speed: float

@onready var _player := get_tree().get_first_node_in_group("player") as Player


var _last_time: int = 0
var _modified_resistance: float
var _modified_speed: float



func _init_data() -> void:
    _modified_resistance = _target.data.thunder_resistance.value * _reduce_resistance
    _modified_speed = _target.data.speed.value * _reduce_speed

    _target.data.thunder_resistance.add_modifier(-_modified_resistance)
    _target.data.speed.add_modifier(-_modified_speed)


func _effect() -> void:
    if Time.get_ticks_msec() - _last_time < _damage_interval * 1000: return
    var info := DamageInfo.create(
        _player, _target, 
        _target.data.max_health.value * _damage_degree, 
        DamageInfo.DamageAttribute.THUNDER,
        0, 0, false, false, false, false, 1 
    )
    FloatTextSystem.show_anomaly_text(info, type)
    DamageSystem.handle_damage(info)
    _last_time = Time.get_ticks_msec()


func _end() -> void:
    _target.data.thunder_resistance.add_modifier(_modified_resistance)
    _target.data.speed.add_modifier(_modified_speed)

